package com.chen.manager.controller;

import cn.hutool.log.Log;
import com.chen.manager.service.ProductService;
import com.chen.model.dto.product.ProductDto;
import com.chen.model.entity.product.Product;
import com.chen.model.entity.product.ProductSku;
import com.chen.model.vo.common.Result;
import com.chen.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cgj
 * @date 3/12/25 7:20 PM
 */
@RestController
@RequestMapping("/admin/product/productList")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 商品的上下架
     */
    @GetMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id,
                               @PathVariable Integer status){
        productService.updateStatus(id,status);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 商品审核
     */
    @GetMapping("updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable Long id,
                                    @PathVariable Integer auditStatus){
        productService.updateAuditStatus(id,auditStatus);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 根据id删除
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Long id){
        productService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);

    }
    /**
     * 根据id查询商品详细信息, 用于回显
     */
    @GetMapping("/{id}")
    public Result<Product> getById(@PathVariable Long id){
        Product product=productService.getById(id);
        return Result.build(product,ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改商品
     */
    @PutMapping("/update")
    public Result update(@RequestBody Product product){
        productService.update(product);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 增加商品
     */
    @PostMapping("/save")
    public Result sava(@RequestBody Product product){
        productService.save(product);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 分页条件查询商品
     * @param pageNum
     * @param pageSize
     * @param productDto
     * @return
     */
    @GetMapping("/showByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<Product>> getByPage(@PathVariable Integer pageNum,
                                               @PathVariable Integer pageSize,
                                               ProductDto productDto){
        PageInfo<Product> pageInfo=productService.getByPage(pageNum,pageSize,productDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
}
